package com.ruoyi.web.controller.ccc3gc;

import com.ccc3gc.mysystem.VO.DeliveryOrderVO;
import com.ccc3gc.mysystem.VO.OrderVO;
import com.ccc3gc.mysystem.VO.SearchParamVO;
import com.ccc3gc.mysystem.bean.DeliveryOrder;
import com.ccc3gc.mysystem.bean.Order;
import com.ccc3gc.mysystem.service.DeliveryOrderService;
import com.ccc3gc.mysystem.service.OrderService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/deliveryOrder")
public class DeliveryOrderController {
    @Autowired
    public DeliveryOrderService deliveryOrderService;
    @Autowired
    public OrderService orderService;

    //添加配送
    @PostMapping("/add")
    public AjaxResult addDeliveryOrder(@RequestBody DeliveryOrder deliveryOrder){
        int rows = deliveryOrderService.insertDeliveryOrder(deliveryOrder);
        if(rows>0){
            Integer orderId = deliveryOrder.getOrderId();
            OrderVO orderVO = orderService.selectOrderByOrderId(orderId);
            Order order= new Order();
            order.setStateId( orderVO.getStateId()+1);
            order.setOrderId(orderId);
            orderService.updateOrder(order);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
    //查询用户端配送中订单列表，以及配送员配送列表，详情
    @PostMapping("/deliveryList")
    public AjaxResult selectDeliveryOrder(@RequestBody SearchParamVO searchParamVO){
        List<DeliveryOrderVO> deliveryOrderVOS = orderService.selectDeliveryOrder(searchParamVO);
        return AjaxResult.success(deliveryOrderVOS);
    }
}
